/*
 *	Copyright © 2013 Changsha Shishuo Network Technology Co., Ltd. All rights reserved.
 *	长沙市师说网络科技有限公司 版权所有
 *	http://www.shishuo.com
 */

package com.hlingsoft.cms.action.manage;

import javax.servlet.http.HttpServletRequest;

import com.hlingsoft.cms.dao.*;
import com.hlingsoft.cms.entity.Consignee;
import com.hlingsoft.cms.entity.MessageStatus;
import com.hlingsoft.cms.entity.OrderInfo;
import com.hlingsoft.cms.entity.Start;
import com.hlingsoft.cms.service.AdminFolderService;
import com.hlingsoft.cms.service.AdminService;
import com.hlingsoft.cms.service.FolderService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.hlingsoft.cms.constant.SystemConstant;
import com.hlingsoft.cms.entity.vo.AdminVo;
import com.hlingsoft.cms.entity.vo.JsonVo;
import com.hlingsoft.cms.exception.ValidateException;
import com.hlingsoft.cms.service.ArticleService;
import com.hlingsoft.cms.service.ConfigService;
import com.hlingsoft.cms.service.HeadlineService;
import com.hlingsoft.cms.service.MediaService;

/**
 * @author 所有action的父类
 */
@Controller
public class ManageBaseAction {

    protected final Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    protected ConfigService configService;

    @Autowired
    protected FolderService folderService;

    @Autowired
    protected ArticleService articleService;

    @Autowired
    protected MediaService attachmentService;

    @Autowired
    protected AdminService adminService;

    @Autowired
    protected HeadlineService headlineService;

    @Autowired
    protected AdminFolderService adminFolderService;

    @Autowired
    protected NewsDao newsDao;

    @Autowired
    protected CommentDao commentDao;

    @Autowired
    protected LikesDao likesDao;

    @Autowired
    protected CommentMessageDao commentMessageDao;

    @Autowired
    protected LikesMessageDao likesMessageDao;

    @Autowired
    protected FocusDao focusDao;

    @Autowired
    protected ConsigneeDao consigneeDao;

    @Autowired
    protected AppUserDao appUserDao;

    @Autowired
    protected FeedbackDao feedbackDao;

    @Autowired
    protected FocusMessageDao focusMessageDao;

    @Autowired
    protected ImageDao imageDao;

    @Autowired
    protected MessageStatusDao messageStatusDao;

    @Autowired
    protected OrderInfoDao orderInfoDao;

    @Autowired
    protected ReportDao reportDao;

    @Autowired
    protected StartDao startDao;

    @Autowired
    protected TagsDao tagsDao;

    @Autowired
    protected TypeDao typeDao;

    @Autowired
    protected GoodsDao goodsDao;


    /**
     * 参数校验
     *
     * @param json json数据Bean
     * @throws ValidateException
     */
    protected <T> void validate(JsonVo<T> json) throws ValidateException {
        if (json.getErrors().size() > 0) {
            json.setResult(false);
            throw new ValidateException("有错误发生");
        } else {
            json.setResult(true);
        }
    }

    /**
     * 从session中获得管理员的信息
     *
     * @param request
     * @return
     */
    protected AdminVo getAdmin(HttpServletRequest request) {
        AdminVo admin = (AdminVo) request.getSession().getAttribute(
                SystemConstant.SESSION_ADMIN);
        return admin;
    }
}
